
//vertex shader
#version 330 core
layout (location = 0) in vec3 position;
layout (location = 1) in vec3 normal;
layout (location = 2) in vec4 vColor;
layout (location = 3) in vec2 texCoord;

out vec4 vertex_color;
out vec3 frag_normal;
out vec3 frag_pos;

uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;

void main()
{
	gl_Position = projection * view * model * vec4(position, 1.0);
	vertex_color = vColor; 
	frag_normal = normal * mat3(model);//mat3(transpose(inverse(model))) * normal; 
	frag_pos = (model * vec4(position, 1.0)).xyz;
}



//fragemnt shader

#version 330 core
in vec4 vertex_color;
in vec3 frag_normal;
in vec3 frag_pos;

out vec4 color;

uniform vec4 light_color;
uniform vec4 light_pos;
uniform vec3 view_pos;

void main()
{
	float ambient_factor = 0.1f;
	vec4 ambient_color = light_color * ambient_factor;//ambient component

	light_dir = normalize(light_pos - frag_pos);
	vec4 diffuse_color = light_color * max(dot(light_dir,frag_normal),0.0f);//diffuse component	

	vec3 refect_dir = reflect(-light_dir,normal);
	vec3 view_dir = normalize(view_pos - frag_pos);
	float spec_strength = 0.5f;
	int spec_shininess = 32;
	float spec_factor = pow(max(dot(refect_dir,view_dir),0.0f),spec_shininess);
	vec4 spec_color = spec_strength * spec_factor * light_color;

	color = (ambient_color + diffuse_color + spec_color) * vertex_color;
}